<template>
  <div>
    <!--    头部-->
    <div style="display: flex; height: 60px; line-height: 60px; border-bottom: 1px solid #eee">
      <div style="width: 300px; display: flex; padding-left: 100px;">
        <div style="width: 150px;">
          <img src="../../assets/logo2.png" alt="" style="width: 140px;">
        </div>
      </div>
      <div style="flex: 1">
        <el-menu :default-active="'1'" class="el-menu-demo" mode="horizontal" router>
          <el-menu-item index="/front/home">首页</el-menu-item>
          <el-menu-item index="/front/ticket">我要购票</el-menu-item>
          <el-menu-item index="/front/article">精彩推文</el-menu-item>
          <el-menu-item index="/front/map">地图</el-menu-item>
          <el-menu-item index="/front/order" v-if="user.username">订单管理</el-menu-item>
          <el-menu-item index="/front/person">我的</el-menu-item>
          <!--          <el-submenu index="2">-->
          <!--            <template slot="title">我的</template>-->
          <!--            <el-menu-item index="/front/item1">订单管理</el-menu-item>-->
          <!--            <el-menu-item index="2-2">选项2</el-menu-item>-->
          <!--            <el-menu-item index="2-3">选项3</el-menu-item>-->
          <!--            <el-submenu index="2-4">-->
          <!--              <template slot="title">选项4</template>-->
          <!--              <el-menu-item index="2-4-1">选项1</el-menu-item>-->
          <!--              <el-menu-item index="2-4-2">选项2</el-menu-item>-->
          <!--              <el-menu-item index="2-4-3">选项3</el-menu-item>-->
          <!--            </el-submenu>-->
          <!--          </el-submenu>-->
        </el-menu>
      </div>
      <div style="width: 200px">
        <div v-if="!user.username" style="text-align: right; padding-right: 30px">
          <el-button @click="$router.push('/login')">登录</el-button>
          <el-button @click="$router.push('/register')">注册</el-button>
        </div>
        <div v-else>
          <el-dropdown style="width: 150px; cursor: pointer; text-align: right">
            <div style="display: inline-block">
              <img :src="user.avatarUrl" alt=""
                   style="width: 30px; border-radius: 50%; position: relative; top: 10px; right: 5px">
              <span>{{ user.nickname }}</span><i class="el-icon-arrow-down" style="margin-left: 5px"></i>
            </div>
            <el-dropdown-menu slot="dropdown" style="width: 100px; text-align: center">
              <el-dropdown-item style="font-size: 14px; padding: 5px 0">
                <router-link to="/front/password">修改密码</router-link>
              </el-dropdown-item>
              <el-dropdown-item style="font-size: 14px; padding: 5px 0">
                <router-link to="/front/person">个人信息</router-link>
              </el-dropdown-item>
              <el-dropdown-item style="font-size: 14px; padding: 5px 0">
                <span style="text-decoration: none" @click="logout">退出</span>
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </div>
    </div>

    <div style="width: 1000px; margin: 0 auto">
      <router-view @refreshUser="getUser"/>
    </div>
    <div class="recommendation">
      <ul>
        <li class="title">热门推荐：</li>
        <li><a href="/e_%E5%91%A8%E6%9D%B0%E4%BC%A6/" title="周杰伦演唱会门票">周杰伦演唱会门票</a></li>
        <li><a href="/e_%E6%9E%97%E4%BF%8A%E6%9D%B0/" title="林俊杰演唱会门票">林俊杰演唱会门票</a></li>
        <li><a href="/e_%E5%88%98%E8%8B%A5%E8%8B%B1/" title="刘若英演唱会门票">刘若英演唱会门票</a></li>
        <li><a href="/e_%E6%A2%81%E9%9D%99%E8%8C%B9/" title="梁静茹演唱会门票">梁静茹演唱会门票</a></li>
        <li><a href="/e_%E6%9E%97%E5%AE%A5%E5%98%89/" title="林宥嘉演唱会门票">林宥嘉演唱会门票</a></li>
        <li><a href="/e_%E6%9D%8E%E5%AE%97%E7%9B%9B/" title="李宗盛演唱会门票">李宗盛演唱会门票</a></li>
        <li><a href="/e_%E5%BC%A0%E9%9F%B6%E6%B6%B5/" title="张韶涵演唱会门票">张韶涵演唱会门票</a></li>
        <li><a href="/e_%E5%AE%AB%E5%B4%8E%E9%AA%8F/" title="宫崎骏音乐会门票">宫崎骏音乐会门票</a></li>
      </ul>
    </div>
    <div class="my">
      <div class="my-w">
        <!-- 头部图片 -->
        <div class="my-top w">
          <div class="l top-div">
            <i class="iconfont mar10 i-ico coE">&#xe69c;</i>
            <i class="l coE">确保真票,&nbsp;&nbsp;购票无忧</i>
          </div>
          <div class="l top-div">
            <i class="iconfont mar10 i-ico coF">&#xe601;</i>
            <i class="l coF">担保交易,&nbsp;&nbsp;放心付款</i>
          </div>
          <div class="l top-div bod-r">
            <i class="iconfont mar10 i-ico co6">&#xe6b8;</i>
            <i class="l co6">安心购票,&nbsp;&nbsp;无票赔付</i>
          </div>
        </div>
        <div class="my-c">
          <div class="w c-w">
            <div class="c-l l">
              <div><a href="">关于我们</a></div>
              <div><a href="">常见问题</a></div>
              <div><a href="mailto:onlysheepen@163.com">联系我们</a></div>
              <div><a href="mailto:onlysheepen@163.com">问题反馈</a></div>
            </div>
          </div>
          <div style="width:300px;margin:0 auto; padding:20px 0;">
            <a target="_blank" href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=41102402000277"
               style="display:inline-block;text-decoration:none;height:20px;line-height:20px;">
              <img src="../../../public/img_1.png" style="float:left;"/>
              <p style="float:left;height:20px;line-height:20px;margin: 0px 0px 0px 5px; color:#939393;">苏ICP备
                41102402000XXX号</p></a>
          </div>

        </div>
      </div>
    </div>
  </div>

</template>

<script>
export default {
  name: "Front",
  data() {
    return {
      user: localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")) : {}
    }
  },
  created() {

  },
  methods: {
    logout() {
      this.$store.commit("logout")
      this.$message.success("退出成功")
    },
    getUser() {
      let username = localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")).username : ""
      if (username) {
        // 从后台获取User数据
        this.request.get("/user/username/" + username).then(res => {
          // 重新赋值后台的最新User数据
          this.user = res.data
        })
      }
    }
  }
}
</script>

<style src="../../static/css/common.css" scoped></style>
<style src="../../static/css/allitems.css" scoped></style>
<style scoped>
/*@import "../../static/css/allitems.css";*/
/*@import "../../static/css/common.css";*/

.item {
  display: inline-block;
  width: 100px;

  text-align: center;
  cursor: pointer
}

.item a {
  color: #1E90FF;
}

.item:hover {
  background-color: LightPink;
}
</style>
